package com.ydcode;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;

import com.ydcode.beans.User;
import com.ydcode.utils.BeanUtil;
import com.ydcode.utils.IDFactory;
import com.ydcode.utils.PropertiesUtil;
import com.ydcode.utils.Prototype;

/**
 * 程序入口
 * 
 * @author YUPENG.LI
 * 
 */
public class Main {

	static Logger logger = Logger.getLogger(Main.class);

	/**
	 * @param args
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 * @throws IllegalArgumentException
	 */
	public static void main(String[] args) throws IllegalArgumentException,
			IllegalAccessException, InvocationTargetException {

		User user = new User();
		user.userid = IDFactory.getSID();
		user.name = "ABCD";
		user.created = new Date().toString();
		user.password = "XXXXXX123";

		List<Prototype> prototypes = BeanUtil.getProperty(User.class);

		HashMap<String, Object> hashMap = new HashMap<String, Object>();

		for (Prototype prototype : prototypes) {
			Method getMethod = prototype.getGetMethod();
			hashMap.put(prototype.getName(), getMethod.invoke(user));
		}

		PropertiesUtil.savePropertiesFile(hashMap, "test.properties", user
				.getClass().toString());
	}
}
